package com.example.dormitorymanagement.repository;

import com.example.dormitorymanagement.model.Occupancy;
import com.example.dormitorymanagement.model.Room;
import com.example.dormitorymanagement.model.Student;
import com.example.dormitorymanagement.model.Occupancy.OccupancyStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface OccupancyRepository extends JpaRepository<Occupancy, Integer> {

    // 根据学生查询入住记录
    List<Occupancy> findByStudent(Student student);

    // 根据房间查询入住记录
    List<Occupancy> findByRoom(Room room);

    // 根据学生和状态查询入住记录
    Optional<Occupancy> findByStudentAndStatus(Student student, OccupancyStatus status);

    // 根据房间和状态查询入住记录列表
    List<Occupancy> findByRoomAndStatus(Room room, OccupancyStatus status);

    // 统计房间中当前入住的学生数量
    long countByRoomAndStatus(Room room, OccupancyStatus status);
}